<?
if (!$argc) { die(__FILE__." must be run from the command line.\n"); }
chdir(dirname(__FILE__));

include "global.php";

// $db->query0("create table tags (project_id int, value varchar(32))");
// $db->query0("CREATE INDEX tags_project_id_index ON tags (project_id)");
// $db->query0("CREATE INDEX tags_value_index ON tags (value)");

$r = $db->query("select * from project");
inc_inclib("query.php");
$map = query2map($db->query("select * from node"),"id","title");

foreach ($r as $e) {
    $pid = $db->sqlint($e["id"]);
    $value = $db->sqlstring(strtolower($map[$e["node_id"]]));
    $db->query0("insert into tags (project_id,value) values ($pid,$value)");
}
